package com.LeeCode;

/**
 * Pow(x, n)
 */

public class Code050 {
    public static void main(String[] args) {
        Code050 c = new Code050();
        System.out.println(c.myPow(2, -10));
    }

    public double myPow(double x, int n) {
        if (n >= 0)
            return quickMul(x, n);
        else {
            return 1.0 / quickMul(x, -n);
        }
    }

    public double quickMul(double x, int n) {
        if (n == 0) return 1;
        double tmp = quickMul(x, n / 2);

        if (n % 2 == 0) return tmp * tmp;
        else return tmp * tmp * x;
    }
}
